package ArrayTest;

public class Test {

    public static void InvertCharacters(String[] str){
        int start=0;
        int end=str.length-1;
        while(start<end){
            String tmp=str[start];
            str[start]=str[end];
            str[end]=tmp;
            start++;
            end--;
        }


    }
    public static String InvertCharacters1 (int k,String str1){
        char[] str=str1.toCharArray();
        for (int i = 0; i < str1.length(); i+=2*k) {

            int start=i;
            int end=Math.min(str1.length()-1,i+k-1);
            //判断最小的如果数组整体小于k说明要整体反转for循环就只循环一次
            //for循环循环一次后在判断end如果大于数组说明后面的数组元素全部要反转小于就只需反转k个就可以了
            while(start<end){
                char tmp=str[start];
                str[start]=str[end];
                str[end]=tmp;
                start++;
                end--;
            }
        }

        return  new String(str);
    }

    public static String repLaseNumber(String str){
        int count=0;//判断整数的个数
        int sOldSize=str.length()-1;//字符串长度
        for (int i = 0; i < sOldSize; i++) {
            if(Character.isDigit(str.charAt(i))){//判断字符是否为整数
                count++;
            }
        }

        char[] chars=new char[str.length()+count*5];
        System.arraycopy(str.toCharArray(),0,chars,0,str.length()-1);//拷贝数组把原数组里数据的拷贝到新数组里

        for (int i = chars.length-1, j=str.length()-1; i <j ;i--,j--) {

            if(!Character.isDigit(str.charAt(j))){
                chars[j]=chars[i];//不是数字就交换放到后面
            }else{
                chars[i]='r';
                chars[i-1]='e';
                chars[i-2]='b';
                chars[i-3]='m';
                chars[i-4]='u';
                chars[i-5]='n';
                i-=5;

            }
        }

        return new String(chars);
    }
    public static void main(String[] args) {
        String[] str=new String[]{"H","E","l","l","o"};
        Test.InvertCharacters(str);
        Test.InvertCharacters1(2,"abcdefg");
    }
}













